


  const API_HEAD = `http://techcherry.cn/playwithapi/`;

  var GetQueryString =(name)=>{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return 'null';
};

var decodeurl =(str)=>{
  var s = "";
  if (str.length == 0) return "";
  s = str.replace(/&amp;/g, "&");
  s = s.replace(/&lt;/g, "<");
  s = s.replace(/&gt;/g, ">");
  s = s.replace(/&nbsp;/g, " ");
  s = s.replace(/&#39;/g, "\'");
  s = s.replace(/&quot;/g, "\"");
  return s;  
}


var isBase64=(str)=>
 {
  console.log(str,'strstr');
  if(str==''){
    return false
  }else{
    return str.indexOf('data:image')>-1; 
  }
}

//去重
var uniq=(array)=>{
  var temp = []; //一个新的临时数组
  array.forEach(x=>{
    if(temp.indexOf(Number(x) ) == -1)  temp.push(Number(x));
    console.log('uniq',temp);

  })
  
  return temp;
}





var showAlert = (wrap,content,id,type)=>{
  
  wrap.append(` <div id="${id}" class="alert alert-${type}">
  <a href="#" class="close" data-dismiss="alert">&times;</a>
  <strong>提示！</strong>${content}  </div>`)
  $(`#${id}`).alert();
}

var getpay=(name)=>{ 
  let pay = 0;
  switch (name) {
    case '请选择': {
      pay = 0
      break;
  }
    case '牛仔拉链': {
        pay = 120
        break;
    }
    case '牛仔纽扣': {
        pay = 120
        break;
    }
    case '夏实训': {
        pay = 90
        break;
    }
    case '短T恤': {
        pay = 40
        break;
    }
    case '长T恤': { 
        pay = 45
        break;
    }
    case '棒球服': {
        pay = 140
        break;
    }

    default:
        break;
}

return pay;

  
}

var checkPhone=(phone)=>{
  var re =/^[1][3,4,5,7,8][0-9]{9}$/;
  return re.test(phone)
}

function isIPhoneX(){
  
  
   if (screen.height == 812 && screen.width == 375){
       //是iphoneX 
       console.log('是iphoneX/XS 系列');
     return true;
     }else{
          //不是iphoneX
          return false; 
         } }


//默认GET方法
var fstHttps =(url,data,succ,type)=>{
  console.log(url,'fsturl');
  
    $.ajax({
            url,
            type:type?type:'POST',
             beforeSend:res=>{
              res.setRequestHeader("token",'safjksdhfjksdbngjksdg' );
            },
            data,

            success: function (res) {
              succ&&succ(res)
            },
            complete:res=>{
              console.log('complete',res.responseText);
            }
        })
}


var Https =(url,data,succ,type,fail,isasync)=>{
  let senddata = {}
  senddata['token'] = '9fghahdbb3489fghbasjd'
  senddata['userid'] = '1'
   for(var k in data){
     senddata[k] = data[k]
   }
  //  console.log(senddata,'senddata');
   
    $.ajax({
            url,
            type:type?type:'POST',
            data:senddata,
            async:isasync=='false'?!1:!0,
            // beforeSend:res=>{
            //   res.setRequestHeader("token","9fghahdbb3489fghbasjd" );
            // },
            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
           
            complete: function (res) {
              console.log('complete--'+url,res);
              if(res.status!=200){
                fail&&fail(JSON.parse(res.responseText))
              }
            },
        })
}

var excelHttps = (url, data, succ, type, fail, isasync) => {
  var senddata = { token: $.cookie('token') }
  if (!senddata.token) { window.location.href = './shopunknwo.html'; return }

  for (var k in data) {
    senddata[k] = data[k]
  }
  console.log(senddata, 'senddata');

  $.ajax({
    url,
    type: type ? type : 'POST',
    data: senddata,
    async: isasync == 'false' ? !1 : !0,
    // beforeSend:res=>{
    //   res.setRequestHeader("token",$.cookie('token') );
    // },
    success: function (res) {
      succ && succ(res)
    },

    complete: function (res) {
      if (res.status != 200) {
        fail && fail(JSON.parse(res.responseText))
      }
    },
  })
}

var formatDate = (date)=>{
 return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
}

var formatDate1 = (sd)=>{
  return sd.getFullYear()+"-"+("0" + (sd.getMonth() + 1)).slice(-2)+"-"+("0" + sd.getDate()).slice(-2);
 }

// 家具


var praypay = (openid,price,size,succ)=>{
  Https(`${API_HEAD}orders/gongpay`
  ,{openid,price,size},res=>{
    succ&&succ(res)
  })
}

var getuser = (openid,succ)=>{
  Https(`${API_HEAD}users/getuser`
  ,{openid},res=>{
    succ&&succ(res)
  })
}

var bind = (data,succ)=>{
  Https(`${API_HEAD}student/bind`
  ,data,res=>{
    succ&&succ(res)
  })
}

var hasadd = (succ)=>{
  Https(`${API_HEAD}dinggou/hasadd`
  ,{openid:localStorage.getItem('openid')},res=>{
    succ&&succ(res)
  })
}

var info_findbyuserid = (id,succ)=>{
  Https(`${API_HEAD}dinggou/bk_findbyuserid`
  ,{id},res=>{
    succ&&succ(res)
  })
}


var addinfo = (data,succ)=>{
  Https(`${API_HEAD}dinggou/mp_add`
  ,data,res=>{
    succ&&succ(res)
  })
}

var canbuy = (openid,succ)=>{
  Https(`${API_HEAD}orders/canbuy`
  ,{openid},res=>{
    succ&&succ(res)
  })
}

var wxlogin = (code,succ)=>{
  fstHttps(`${API_HEAD}login/wxcheck`
  ,{code,},res=>{
    succ&&succ(res)
  },'POST')
}

var uploadimg = (base64str,succ)=>{
  Https( `${API_HEAD}upload/upload`,{base64str} ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}

var idvadd = (data,succ)=>{
  Https( `${API_HEAD}idv/add`,data ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}
var 根据id获取idv = (userid,succ)=>{
  Https( `${API_HEAD}idv/bk_getdetail`,{userid} ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}

var 注册 = (data,succ)=>{
  Https( `${API_HEAD}login/register`,data ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}

var 登录 = (data,succ)=>{
  Https( `${API_HEAD}login/h5login`,data ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}












  







